home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
366_01
/
ue311c1.arc
/
AMIGADOS.C
next >
Wrap
C/C++ Source or Header
|
1990-08-16
|
22KB
|
892 lines
/* AMIGADOS.C: Operating specific I/O and Spawning functions
for MicroEMACS 3.10
(C)Copyright 1988 by Daniel M. Lawrence
*/
#include <stdio.h>
#include "estruct.h"
#if AMIGA
#include <exec/types.h>
#include <exec/io.h>
#include <intuition/intuition.h>
#include <devices/console.h>
#include "eproto.h"
#include "edef.h"
#include "elang.h"
#define INTUITION_REV 0L
#define NEW 1006L
#define CRWIDTH 8
#define CRHEIGHT 8
struct IntuitionBase *IntuitionBase;
struct Window *win;
struct IOStdReq con; /* ptr to console device driver handle */
/* Intuition Function type declarations */
struct IntuitionBase *OpenLibrary();
struct Window *OpenWindow();
struct IntuiMessage *GetMsg();
typedef struct {
short rw_code; /* normal keycode to generate */
short rw_scode; /* shifted " */
short rw_ccode; /* control " */
} RKEY;
/* raw keycode scan code to emacs keycode translation table */
RKEY keytrans[0x60] = {
/* CODE NORM SHIFT CTRL */
/* 0x00,*/ '`', '~', 0,
/* 0x01,*/ '1', '!', 0,
/* 0x02,*/ '2', '@', 0,
/* 0x03,*/ '3', '#', 0,
/* 0x04,*/ '4', '$', 0,
/* 0x05,*/ '5', '%', 0,
/* 0x06,*/ '6', '^', 0,
/* 0x07,*/ '7', '&', 0,
/* 0x08,*/ '8', '*', 0,
/* 0x09,*/ '9', '(', 0,
/* 0x0a,*/ '0', ')', 0,
/* 0x0b,*/ '-', '_', 0,
/* 0x0c,*/ '=', '+', 0,
/* 0x0d,*/ '\\', '|', 0,
/* 0x0e,*/ 0, 0, 0,
/* 0x0f,*/ 0, 0, 0,
/* 0x10,*/ 'q', 'Q', CTRL|'Q',
/* 0x11,*/ 'w', 'W', CTRL|'W',
/* 0x12,*/ 'e', 'E', CTRL|'E',
/* 0x13,*/ 'r', 'R', CTRL|'R',
/* 0x14,*/ 't', 'T', CTRL|'T',
/* 0x15,*/ 'y', 'Y', CTRL|'Y',
/* 0x16,*/ 'u', 'U', CTRL|'U',
/* 0x17,*/ 'i', 'I', CTRL|'I',
/* 0x18,*/ 'o', 'O', CTRL|'O',
/* 0x19,*/ 'p', 'P', CTRL|'P',
/* 0x1a,*/ '[', '{', 0,
/* 0x1b,*/ ']', '}', 0,
/* 0x1c,*/ 0, 0, 0,
/* 0x1d,*/ '1', SPEC|'>', 0,
/* 0x1e,*/ '2', SPEC|'N', 0,
/* 0x1f,*/ '3', SPEC|'V', 0,
/* 0x20,*/ 'a', 'A', CTRL|'A',
/* 0x21,*/ 's', 'S', CTRL|'S',
/* 0x22,*/ 'd', 'D', CTRL|'D',
/* 0x23,*/ 'f', 'F', CTRL|'F',
/* 0x24,*/ 'g', 'G', CTRL|'G',/* 0x25,*/ 'h', 'H', CTRL|'H',
/* 0x26,*/ 'j', 'J', CTRL|'J',
/* 0x27,*/ 'k', 'K', CTRL|'K',
/* 0x28,*/ 'l', 'L', CTRL|'L',
/* 0x29,*/ ';', ':', 0,
/* 0x2a,*/ 39, 34, 0,
/* 0x2b,*/ 0, 0, 0,
/* 0x2c,*/ 0, 0, 0,
/* 0x2d,*/ '4', SPEC|'B', 0,
/* 0x2e,*/ '5', 0, 0,
/* 0x2f,*/ '6', SPEC|'F', 0,
/* this key is probably mapped on forign AIMIGA keyboards */
/* 0x30,*/ 0, 0, 0,
/* 0x31,*/ 'z', 'Z', CTRL|'Z',
/* 0x32,*/ 'x', 'X', CTRL|'X',
/* 0x33,*/ 'c', 'C', CTRL|'C',
/* 0x34,*/ 'v', 'V', CTRL|'V',
/* 0x35,*/ 'b', 'B', CTRL|'B',
/* 0x36,*/ 'n', 'N', CTRL|'N',
/* 0x37,*/ 'm', 'M', CTRL|'M',
/* 0x38,*/ ',', '<', 0,
/* 0x39,*/ '.', '>', 0,
/* 0x3a,*/ '/', '?', 0,
/* 0x3b,*/ 0, 0, 0,
/* 0x3c,*/ '.', SPEC|'D', 0,
/* 0x3d,*/ '7', SPEC|'<', 0,
/* 0x3e,*/ '8', SPEC|'P', 0,
/* 0x3f,*/ '9', SPEC|'Z', 0,
/* 0x40,*/ ' ', SHFT|' ', 0,
/* 0x41,*/ CTRL|'H', SHFT|'D', 0,
/* 0x42,*/ CTRL|'I', SHFT|'I', 0,
/* 0x43,*/ CTRL|'M', CTRL|'M', CTRL|'M',
/* 0x44,*/ CTRL|'M', CTRL|'M', CTRL|'M',
/* 0x45,*/ CTRL|'[', 0, 0,
/* 0x46,*/ SPEC|'D', 0, 0,
/* 0x47,*/ 0, 0, 0,
/* 0x48,*/ 0, 0, 0,
/* 0x49,*/ 0, 0, 0,
/* 0x4a,*/ '-', 0, 0,
/* 0x4b,*/ 0, 0, 0,
/* 0x4c,*/ SPEC|'P', SHFT|SPEC|'P', CTRL|SPEC|'P',
/* 0x4d,*/ SPEC|'N', SHFT|SPEC|'N', CTRL|SPEC|'N',
/* 0x4e,*/ SPEC|'F', SHFT|SPEC|'F', CTRL|SPEC|'F',
/* 0x4f,*/ SPEC|'B', SHFT|SPEC|'B', CTRL|SPEC|'B',
/* 0x50,*/ SPEC|'1', SHFT|SPEC|'1', CTRL|SPEC|'1',
/* 0x51,*/ SPEC|'2', SHFT|SPEC|'2', CTRL|SPEC|'2',
/* 0x52,*/ SPEC|'3', SHFT|SPEC|'3', CTRL|SPEC|'3',
/* 0x53,*/ SPEC|'4', SHFT|SPEC|'4', CTRL|SPEC|'4',
/* 0x54,*/ SPEC|'5', SHFT|SPEC|'5', CTRL|SPEC|'5',
/* 0x55,*/ SPEC|'6', SHFT|SPEC|'6', CTRL|SPEC|'6',
/* 0x56,*/ SPEC|'7', SHFT|SPEC|'7', CTRL|SPEC|'7',
/* 0x57,*/ SPEC|'8', SHFT|SPEC|'8', CTRL|SPEC|'8',
/* 0x58,*/ SPEC|'9', SHFT|SPEC|'9', CTRL|SPEC|'9',
/* 0x59,*/ SPEC|'0', SHFT|SPEC|'0', CTRL|SPEC|'0',
/* 0x5a,*/ '(', 0, 0,
/* 0x5b,*/ ')', 0, 0,
/* 0x5c,*/ '/', 0, 0,
/* 0x5d,*/ '*', 0, 0,
/* 0x5e,*/ 0, 0, 0,
/* 0x5f,*/ SPEC|'?', 0, 0,
};
/* some keyboard keys current states */
int r_shiftflag; /* right shift key */
int l_shiftflag; /* left shift key */
int r_altflag; /* right alt key */
int l_altflag; /* left alt key */
int r_amiflag; /* right amiga key */
int l_amiflag; /* left amiga key */
int ctrlflag; /* control key */
int lockflag; /* shift lock key */
/* output buffers and pointers */
#define OBUFSIZE 1024L
#define IBUFSIZE 64 /* this must be a power of 2 */
char out_buf[OBUFSIZE+1]; /* output character buffer */
int out_ptr = 0; /* index to next char to put in buffer */
/* input buffers and pointers */
#define IBUFSIZE 64 /* this must be a power of 2 */
unsigned char in_buf[IBUFSIZE]; /* input character buffer */
int in_next = 0; /* pos to retrieve next input character */
int in_last = 0; /* pos to place most recent input character */
in_init() /* initialize the input buffer */
{
in_next = in_last = 0;
}
in_check() /* is the input buffer non-empty? */
{
if (in_next == in_last)
return(FALSE);
else
return(TRUE);
}
in_put(event)
int event; /* event to enter into the input buffer */
{
in_buf[in_last++] = event;
in_last &= (IBUFSIZE - 1);
}
int in_get() /* get an event from the input buffer */
{
register int event; /* event to return */
event = in_buf[in_next++];
in_next &= (IBUFSIZE - 1);
return(event);
}
/*
* This function is called once to set up the terminal device streams.
* On VMS, it translates TT until it finds the terminal, then assigns
* a channel to it and sets it raw. On CPM it is a no-op.
*/
ttopen()
{
struct NewWindow new_win;
int i;
#if AZTEC
extern Enable_Abort; /* Turn off ctrl-C interrupt */
Enable_Abort = 0; /* for the Manx compiler */
#endif
/* open the intuition library */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV);
if (IntuitionBase == NULL) {
printf("%%Can not open Intuition\n");
exit(-1);
}
/* initialize the new windows attributes */
new_win.LeftEdge = 0;
new_win.TopEdge = 0;
new_win.Width = 640;
new_win.Height = 200;
new_win.DetailPen = 0;
new_win.BlockPen = 1;
new_win.Title = (unsigned char *)"MicroEMACS 3.10g/Amiga";
new_win.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
WINDOWDRAG | WINDOWDEPTH | WINDOWSIZING | SIZEBRIGHT |
RMBTRAP | NOCAREREFRESH;
new_win.IDCMPFlags = CLOSEWINDOW | NEWSIZE | MOUSEBUTTONS |
RAWKEY;
new_win.Type = WBENCHSCREEN;
new_win.FirstGadget = NULL;
new_win.CheckMark = NULL;
new_win.Screen = NULL;
new_win.BitMap = NULL;
new_win.MinWidth = 100;
new_win.MinHeight = 25;
new_win.MaxWidth = 640;
new_win.MaxHeight = 200;
/* open the window! */
win = (struct Window *)OpenWindow(&new_win);
if (win == NULL) {
printf("%%Can not open a window\n");
exit(-2);
}
/* and open up the console for output */
con.io_Data = (APTR)win;
OpenDevice("console.device", 0, &con, 0);
/* and init all the keyboard flags */
r_shiftflag = FALSE;
l_shiftflag = FALSE; r_altflag = FALSE;
l_altflag = FALSE;
r_amiflag = FALSE;
l_amiflag = FALSE;
ctrlflag = FALSE;
lockflag = FALSE;
/* initialize our private event queue */
in_init();
/* set the current sizes */
newwidth(TRUE, 77);
newsize(TRUE, 23);
/* on all screens we are not sure of the initial position
of the cursor */
ttrow = 999;
ttcol = 999;
}
/*
* This function gets called just before we go back home to the command
* interpreter. On VMS it puts the terminal back in a reasonable state.
* Another no-operation on CPM.
*/
ttclose()
{
/* make sure there is no pending output */
ttflush();
/* and now close up shop */
CloseDevice(&con);
CloseWindow(win);
OpenWorkBench();
}
/*
* Write a character to the display. On VMS, terminal output is buffered, and
* we just put the characters in the big array, after checking for overflow.
* On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
* MS-DOS (use the very very raw console output ro